<template>
	<view class="xb-page">
		<view class="xb-page-container">
			<view class="xb-textbutton-cell">
				<view @click="create" class="xb-textbutton  page-button-right">添加新机构</view>
			</view>
			<view class="page-section-title ">
				<label class="page-section-label">创建的机构</label>
			</view>
			<view class="xb-list">
				<view class="xb-list-cell " hover-class="xb-list-cell-hover"   v-for="(org,index) in orglist" :key="index" @click="change(index)">
					<view class="uni-list-cell-navigate">
						<view class="uni-flex uni-row" style="width: 100%;justify-content: space-between; align-items: center;">
							<view class=" uni-flex uni-row org-list-item-head" style="align-items: center;">
								<view class="xb-item-desc-dark">{{org.name}}</view>
							</view>
							<view class="page-jigz-cell">
								机构所有者
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import pageHead from '../../../components/page-head.vue';
	import { queryorgs } from '../../../api/getData.js';
	import {
		mapActions,
		mapState,
		mapGetters,
		mapMutations
		
	} from 'vuex'
	
	export default {
		data() {
			return {
				formdata:{
				   orgid:0,
					   
				},
				orglist: [{
						"name": "咪咪舞蹈学校"
					},
					{
						"name": "旺旺音乐寻小"
					}
				]
			}

		},
		onLoad: function() {
			this.initData();

		},
		onPullDownRefresh: function() {
			this.initData();

		},
		methods: {
			...mapMutations(['setOrgid']),
			initData: async function(e) {
				uni.showNavigationBarLoading();
				const res = await queryorgs(formdata);
				if (res.success = true) {

					uni.hideNavigationBarLoading();
					this.orglist.push(res.data.values);
				} else {
					uni.hideNavigationBarLoading();
				}

			},
			create: function() {
				uni.navigateTo({
					url: "addorg"
				});

			},
			//选择机构
			change: function(e) {
				uni.showModal({
					title: '提示',
					content: '确认选择该机构?',
					success: function(res) {
						if (res.confirm) {
							setOrgid(orgid);
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			joinorg: async function(orgid) {
				const res = await joinorg({
					'orgid': orgid
				});
				if (res.success == true) {

				} else {

				}

			}

		}
	}
</script>

<style scoped>
	@import "../../../common/uni.css";
	@import "../../../common/xb.css";

	.page-button-right {
		position: absolute;
		right: 3%;
		top: 30%;
	}

	.org-list-item-head {
		margin-left: 30px;
	}

	.page-section-label {
		margin-bottom: 20px;
	}

	.org-list-item-head .image {
		width: 100px;
		height: 100px;
	}

	.org-list-item-tail {
		padding-right: 30px;
	}

	.page-sec-title {
		height: 30px;
		margin-bottom: 2px;
	}

	.page-jigz-cell {
		padding-left: 20px;
		padding-right: 20px;
		padding-top: 10px;
		padding-bottom: 10px;
		font-size: 25px;
		color: #000000;
		background-color: #F4F8FB;
	}
</style>
